<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/wesite/view/common/base.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>修改手机绑定</title>
    <%@ include file="/wesite/view/common/common.jsp"%>
    <style type="text/css">
        html,body{background:#fff;}
        .loginbox.signbox{
            margin:0;
        }
    </style>
</head>
<body>
<div class="loginbox signbox">
    <div class="login-input" id="page1">
        <div class="input-text"><span>手机号</span><input name="uphone"  type="hidden" readonly="readonly"  value="${user.loginphone}"  >
            <div class="phone-num">${user.loginphone.substring(0,3) }*****${user.loginphone.substring(8,user.loginphone.length()) }</div>
        </div>
        <div class="input-text bor-none"><span>验证码</span><input class="code" name="oldsmscode" type="text" placeholder="填写短信校验码">
            <span class="send"><a href="javascript:tosendsms();" id="yzmbtn" class="yzm-btn">获取验证码</a></span>
        </div>
        <div class="itemTip" id="itemTip_old"></div>

    </div>
    <input class="page1-btn" type="button" value="下一步" onclick="tonext()">

    <div class="login-input hide" id="page2">
        <div class="input-text"><span>新手机号</span><input name="newphone"  type="text" placeholder="请输入新绑定号码" > </div>
        <div class="itemTip" id="itemTip_p"></div>
        <div class="input-text bor-none"><span>验证码</span><input class="code" name="newsmscode" type="text" placeholder="填写短信校验码">
            <span class="send"><a href="javascript:tosendsms2();" id="yzmbtn2" class="yzm-btn">获取验证码</a></span>
        </div>
        <div class="itemTip" id="itemTip_s"></div>
    </div>
    <input class="page2-btn" type="button" value="下一步" onclick="tonext2()" style="display: none;">
</div>
</div>
</div>
</body>
</html>
<script src="${webctx}/script/sms.js"></script>

<script>
    var toast = new auiToast({})
    function tosendsms(){
        sendsms($("[name='uphone']").val(),'changephone','yzmbtn');
    }
    function tosendsms2(){
        if($("[name='newphone']").val()==$("[name='uphone']").val()){
            toast.fail({
                title : "请输入新手机号",
                duration : 1000
            })

        }else if(!$w.isMobile($("[name='newphone']").val())){
            toast.fail({
                title : "请输入正确手机号",
                duration : 1000
            })
        }else
            sendsms($("[name='newphone']").val(),'changephone','yzmbtn2');
    }
    
    function tonext(){
        $("#page1 .itemTip").text('');
        $w.httpRequest({
            url:"${ctx}/we/user/checksmscode",
            data:{"mobile":$("[name='uphone']").val(),"smscode":$("[name='oldsmscode']").val()},
            ok:function(ret){
                if(ret.Data=='true'){
                    $("#page1").hide();
                    $(".page1-btn").hide();
                    $("#page2").show();
                    $(".page2-btn").show();
                    curlimit=0;
                    smssending=false;
                }else  toast.fail({
                    title : "验证码错误或失效",
                    duration : 1000
                })
                    //$("#itemTip_old").text('验证码错误或失效');
            }
        })
    }
    function tonext2() {
        $("#page2 .itemTip").text('');
        if(!$w.isMobile($("[name='newphone']").val())){
            toast.fail({
                title : "请输入正确手机号",
                duration : 1000
            })
        }else{
            $w.httpRequest({
                url:"${ctx}/we/user/wechangephone",
                data:{"oldphone":$("[name='uphone']").val(),"newphone":$("[name='newphone']").val(),"oldsmscode":$("[name='oldsmscode']").val(),"newsmscode":$("[name='newsmscode']").val()},
                ok:function(ret){
                    window.location.href="${ctx}/we/user/wehome"
                },fail:function(ret){
                    toast.fail({
                        title : ret.MsgDesc,
                        duration : 1000
                    })
                    return false;
                }
            })
        }
    }

</script>
